package com.bangyu.monitor.modular.system.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.bangyu.monitor.core.util.FormatUtil;
import com.bangyu.monitor.modular.system.biz.DataViewBiz;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @Auther: zhangxue
 * @Date: 19/4/26 12:51
 * @Description:
 */
@Controller
@RequestMapping("/dataView/")
@Slf4j
public class DataViewController extends BaseController {

    @Autowired
    private DataViewBiz biz;

    /**
     * 实时数据
     * @return
     */
    @ResponseBody
    @RequestMapping("/realTimeData")
    public ResponseData realTimeData(@RequestParam("beamNo") String beamNo,@RequestParam("startTime") Long startTime){
        return ResponseData.success(biz.queryRealTimeData(beamNo,startTime));
    }

    /**
     * 突发荷载
     * @param beamNo
     * @return
     */
    @ResponseBody
    @RequestMapping("/payloadRecoverQuery")
    public ResponseData payloadRecoverQuery(@RequestParam("beamNo") String beamNo,
            @RequestParam(value = "startDate",required = false) Integer startDate,
            @RequestParam(value = "endDate",required = false) Integer endDate){
        return ResponseData.success(biz.payloadRecoverQuery(beamNo,startDate,endDate));
    }

    /**
     * 轻型/重型荷载数量
     * @param beamNo
     * @return
     */
    @ResponseBody
    @RequestMapping("/payloadCount")
    public ResponseData payloadCount(@RequestParam("beamNo") String beamNo,@RequestParam(value = "startDate",required = false) Integer startDate,
            @RequestParam(value = "endDate",required = false) Integer endDate){
        return ResponseData.success(biz.queryCountByPayloadType(beamNo,startDate,endDate));
    }

    /**
     * 挠度极限预警
     * @param beamNo
     * @param startDate
     * @param endDate
     * @return
     */
    @ResponseBody
    @RequestMapping("/extremityCount")
    public ResponseData extremityBendValue(@RequestParam("beamNo") String beamNo,@RequestParam(value = "startDate",required = false) Integer startDate,
            @RequestParam(value = "endDate",required = false) Integer endDate){
        return ResponseData.success(biz.extremityCount(beamNo,startDate,endDate));
    }

    /**
     * 每年的静态挠度值
     * @param beamNo
     * @return
     */
    @ResponseBody
    @RequestMapping("/staticStandBendByYear")
    public ResponseData staticStandBendByYear(@Param("beamNo") String beamNo){
        return ResponseData.success(biz.queryStaticStandValueByYear(beamNo));
    }

     /**
     * 桥梁的监控信息汇总
     * @return
     */
    @RequestMapping("/monitorInfoSummary")
    @ResponseBody
    public ResponseData monitorInfoSummary(){
        Date now = new Date();
        Integer startDate = FormatUtil.parseDate2Int(now);
        Integer endDate = startDate;
        return ResponseData.success(biz.monitorInfoSummary(startDate,endDate));
    }






}
